def f(primes):
    for i in range(2, int(primes**0.5)+1):
        if primes % i == 0:
            return False
    return True
    
s=""
no=0
for i in input().split():
    if i == "zero":
        s+= '0'
    elif i =="one":
        s+='1'
    elif i=="two":
        s+='2'
    elif i=="three":
        s+= '3'
    elif i=="four":
        s+= '4'
    elif i=="five":
        s+= '5'
    elif i=="six":
        s+= '6'
    elif i=="seven":
        s+= '7'
    elif i=="eight":
        s+='8'
    elif i=="nine":
        s+= '9'
    else:
        wrong = 1
        break
    
if no == 1 or len(s) != 3:
    print("Wrong input")
else:
    s = int(s)

    nmin = 0
    nmax = 0
    
    for i in range(s+1, 1000):
        if f(i):
            nmax=i
            break
        
    for i in range(s-1, 99, -1):
        if f(i):
            nmin=i
            break
    
    if s-nmin > nmax-s:
        print(nmax)
    else:
        print(nmin)
